<template>
	<view :style="{'width':'100%','height':pageHeight+'px'}">
		<view>
			<image :src="loginbg" style="width:100%;height:400upx"></image>
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<!-- #endif -->
	  <view class="login">  
	    <view class="userdom">
	      <view class="itemView">
			  <view style="height:60upx;font-size:16px;font-weight: bold;">手机号</view>
	        <input class="input" name="userName" v-model='username' placeholder="请输入用户名" placeholder-style="color:#9f9d9e;"
	        />
			</view>
	      <view class="itemView">
			  <view style="height:60upx;font-size:16px;font-weight: bold;">密码</view>
				<input v-if="isPassword" class="input" v-model="password" :password='isPassword' placeholder="请输入密码" placeholder-style="color:#9f9d9e;"/>
			</view>
		</view>
		<view bindtap="getUserInfo" class="wjmm">忘记密码?</view>
	    <view class="logbtn">
	      <text class="logbtnt" @click="onLogin">登录</text>
	    </view>
		<view class="reg">
		  <navigator :url="`../student/register/index?cardid=${openid}`">
			  <text class="regbtnt">注册</text>
		  </navigator>
		</view>
	  </view>
	</view>
</template>

<script>
	import {
	  userAuthSession,
	  userLoginForWechatMini,
	  smsSend,
	  userLogin
	} from '@/api/auth'
	import {
	 getUserInfo,
	 getTreeData
	} from '@/api/user'
	export default {
		data() {
			return {
				show: true,
				columns: [[],[]],
				columnData: [[]],
				scolArr:[[],[]],
				deptArr:[[]],
				pageHeight:uni.getSystemInfoSync().windowHeight,
				username:'',
				loginbg:'',
				password:'123456',
				radio: '1',
				scode:'',
				rcode:'',
				rantName:'',
				openid:'',
				index:0,
				title:'',
				content:'',
				showUser:false,
				rantCateDia:false,
				hasUserInfo:false,
				gysbs:false,
				wxCode:'',
				imgpath:'',
				gysloginstate:'',
				isPassword:true,
				restaurantInfo:[],
				scolRentData:[],
				rcodePicker:[],
				checkboxValue1:[],
				userinfo:{},
			}
		},
		onShow(){
			
		},
		onLoad(options){
			this.loginbg = this.picUrl + 'loginbg.png'
			// this.pageHeight = uni.getSystemInfoSync().windowHeight
		},
		created(){
			this.username = uni.getStorageSync("createBy")
		},
		methods: {
			onLogin(){
			    if (this.username == '') {
					uni.showToast({
						title: "请输入用户名",
						icon: 'none',
						duration: 2000
					});
					return;
			    }
			    if (this.password == '') {
					uni.showToast({
						title: "请输入密码",
						icon: 'none',
						duration: 2000
					});
					return;
			    }
				
			    // app.loginRole = this.data.radio
			    var params = {
				  username: this.username,
				  password: this.password 
			    }
			      // let params = new FormData()
			      // params.append("ulogin",username)
			      // params.append("upwd",password)
			    let _this = this;
				userLogin(params).catch(error=> {
					
				   if(error.data.code==200){
					   uni.setStorageSync("accessToken",error.data.token)
					    _this.getUser(params)
					}else{
						uni.showToast({
							title: error.data.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})			
			},
			getUser(pars){
			    let _this = this
				getUserInfo(pars).catch(response=>{
				   if(response.data.code==200){
						response.data.data.password = pars.password
						uni.setStorage({
							key: 'userifo',
							data: JSON.stringify(response.data.data),
							success: function () {
								uni.setStorageSync('userId',response.data.data.userId)
								uni.setStorageSync('createBy',response.data.data.userName)
								if(response.data.data.userType=="02"){
									//学生
									uni.redirectTo({
										url: "chooseRant"
									})	
								}else if(response.data.data.userType=="01"){
									//商户
									uni.redirectTo({
										url: "../../pageA/shop/index"
									})	
								}else if(response.data.data.userType=="09"){
									//教职工
								}else if(response.data.data.userType=="10"){
									//家属
								}else{
									
								}
							}
						})
				   }
			   })
			}
		}
	}
</script>

<style>
	.uni-page-head{display:none}
	.reg{margin-top:10upx}
	.tpbgimg{width:100%;height:60upx;position:absolute;z-index: 111;}
	.nav_logo{
	  float: left;
	  margin-left: 22rpx;
	  margin-top: 10upx;
	  margin-right: 15rpx;
	  display: block;
	  width:61rpx;
	  height:50rpx;
	}
	.empty_custom{
	  height: 70px;
	  width: 100%;
	}
	.van-picker__toolbar{
	  position: absolute;
	    width: 100%;
	    z-index: 999;
	}
	.wjmm{margin-top:10rpx;color:#9f9d9e}
	.login{padding:10upx 20upx 10upx;border-top-left-radius: 15rpx;border-top-right-radius: 15rpx;}
	.userdom{margin-top:1rem;}
	.itemView{line-height:100rpx;margin-top:20rpx;border-bottom:1px solid #9f9d9e;}
	.itemView input{width:100%;height:100rpx;line-height:100rpx;}
	.pwdImage{width:50rpx;height:50rpx}
	.pwdImage image{width:50rpx;height:50rpx}
	.logradio{margin-top:40rpx;color:#ffffff;display: flex;align-items: center;}
	.logbtn{width:100%;margin:100upx auto 0upx;}
	.regbtnt{width:100%;background:#f4f4f4;height:110rpx;line-height:110rpx;font-size:1.2rem;color:#000000;text-align: center;border-radius: 10px;display:block;margin-top:30rpx}
	.logbtnt{width:100%;background:#1e8550;height:110rpx;line-height:110rpx;font-size:1.2rem;color:#ffffff;text-align: center;border-radius: 10px;display:block;margin-top:50rpx}
	.zbcss{width:100%;text-align: center;color:#fff;margin-top:20rpx;text-decoration-line: underline;}
	/* 自定义导航栏结束 */
</style>
